package config

import (
	"fmt"
	"github.com/spf13/viper"
	"os"
	"time"
)

var (
	v *viper.Viper
)

// Load 加载配置文件
func Load(fileName string) {
	v = viper.New()
	v.SetConfigFile(fileName)
	v.SetConfigType("yaml")
	if err := v.ReadInConfig(); err != nil {
		fmt.Printf("read config failed: %s\n", fileName)
		fmt.Printf("%s\n", err.Error())
		os.Exit(-1)
		return
	}
}

func Get(key string) interface{}                             { return v.Get(key) }
func GetString(key string) string                            { return v.GetString(key) }
func GetBool(key string) bool                                { return v.GetBool(key) }
func GetInt(key string) int                                  { return v.GetInt(key) }
func GetInt32(key string) int32                              { return v.GetInt32(key) }
func GetInt64(key string) int64                              { return v.GetInt64(key) }
func GetDuration(key string) time.Duration                   { return v.GetDuration(key) }
func GetStringMapString(key string) map[string]string        { return v.GetStringMapString(key) }
func GetStringMapStringSlice(key string) map[string][]string { return v.GetStringMapStringSlice(key) }
